#ifndef SCOPED_PTR_H_
#define SCOPED_PTR_H_

#include <stddef.h>
#include <cassert>

template<typename Type>
class scoped_ptr {
 public:
  scoped_ptr(Type* t)
      : t_(t) {
  }
  ~scoped_ptr() {
    delete t_;
  }

  void reset(Type* t) {
    if (t_ != NULL) {
      delete t_;
    }
    t_ = t;
  }

  Type* get() const {
    return t_;
  }
  Type* release() {
    Type* tmp = t_;
    t_ = NULL;
    return tmp;
  }
  Type* operator ->() {
    assert(t_ != NULL);
    return t_;
  }

  Type& operator *() {
    assert(t_ != NULL);
    return *t_;
  }
  const Type& operator *() const {
    assert(t_ != NULL);
    return *t_;
  }

 private:
  Type* t_;

  scoped_ptr(const scoped_ptr&);
  void operator =(const scoped_ptr&);
};

#endif /* SCOPED_PTR_H_ */
